#!/bin/tcsh -ef
#############################################################################
#                                                                           #
# Title: Calculate crystal-weighted reconstruction     		           		#
#                                                                           #
# (C) 2dx.org, GNU Plublic License.                                         #
#                                                                           #
# Created..........: 29/07/2016                                             #
# Last Modification: 29/07/2016                                             #
# Author...........: 2dx.org                                                #
#                                                                           #
#############################################################################
#
# SORTORDER: 11
#
#
# MANUAL: This script launches FREALIGN in reconstruction mode to calculate a 3D map of the crystal-weighted particles with the alignment parameters determined during refinement.
#
# MANUAL: This script is based on the frealign_calc_reconstruction script distributed with FREALIGN v9.11, which was modified to support FREALIGN launching from an arbitrary directory.
#
# DISPLAY: SPR_DIR
# DISPLAY: SPR_CRYSTALREC_DIR
# DISPLAY: SPR_FRLCycle
#
#$end_local_vars
#

set SPR_FRLCycle = ""

set bin_2dx = ""
set proc_2dx = ""
set dir_frealign = ""

set scriptname = RunWeightedReconstructionFREALIGN

set SPR_DIR = ""
set SPR_CRYSTALREC_DIR = ""

set SPR_CRYSTALREC_DIR = ${SPR_DIR}/FREALIGN/${SPR_CRYSTALREC_DIR}/

#$end_vars

set ccp4_setup = 'y'
source ${proc_2dx}/initialize
#

if ( -e LOGS/${scriptname}.results ) then
	mv LOGS/${scriptname}.results LOGS/${scriptname}.results.old
endif

# There's some issue with ${PWD} and {$OLDPWD} in csh, so just to be safe:
set SAVEPATH = ${PWD}

cd ${SPR_CRYSTALREC_DIR}

${dir_frealign}/bin/frealign_calc_reconstruction ${SPR_FRLCycle}

cd ${SAVEPATH}

echo ":: "
echo ":: Reconstruction with FREALIGN has been launched."
echo ":: This may take some time to complete."
echo ":: For detailed information please check ${SPR_CRYSTALREC_DIR}/frealign.log"
echo ":: "
